﻿/**********************************************
 * 功能名称：中间产品相关参数信息录入页面
编写人：  杨莹
建立时间： 杨 2008年11月8日
说明：
加载页面时，根据当前用户ID查询出责任部门，列表显示其作业中心列表。
作业中心列表中选择后，列表出作业中心中间体；
选择作业中心中间体，录入当前中间体的相关W系数信息。
 **************************************************************/


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hisun.Models;
using Hisun.Controllers;
using System.Text;
using System.Collections.Generic;


namespace Hisun.View.PIPDeliverInfo
{
    public partial class PIPInfoForW : AbcPageBase
    {
        HisunDBDataContext db = new HisunDBDataContext();
        public string alter;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


                var CurrentUserCenterId = (from a in db.TAbc_JS_Users where a.操作员ID == Session[ServerVars.sysSessionUserName].ToString() select new { a.责任部门ID }).Single();
                DropDownList_CostCenterId.Items.Clear();
            
             
                FillData2DropDownList(Convert.ToInt32(CurrentUserCenterId.责任部门ID));


            }
        }


            
        //查询当前操作员对应的作业中心列表
        private void FillData2DropDownList(int CenterID)
        {
            ChildCenterList myCenter = new ChildCenterList(CenterID);

            var myCenterFilters = myCenter.CostCenterlist.Where(p => new string[] { "BF", "BG", "BZ" }.Contains(p.类型) && p.停用 == false);
 
            
            foreach (var MylistItem in myCenterFilters)
            {

                
                ListItem InsertItem = new ListItem(MylistItem.作业中心名称 + "(" + MylistItem.作业中心ID.ToString() + ")", MylistItem.作业中心ID.ToString());
                   
                DropDownList_CostCenterId.Items.Add(InsertItem);
            }

 
        }
  

        protected void DropDownList_Check_SelectedIndexChanged(object sender, EventArgs e)
        {
            TextBox_DaiFanGongPishi.Text = "0";//待返工批时
            TextBox_DaiFanGongPishu.Text = "0";//待返工批数
            TextBox_DaiJianPishi.Text = "0";//待检批时
            TextBox_DaiJianPishu.Text = "0";//待检批数
            TextBox_JieChunPiShi.Text = "0";//结存批时
            TextBox_JieChunPiShu.Text = "0";//结存批数
            TextBox_MuYeHuiShouLv.Text = "0";//母液回收率
            TextBox_MuYeShuLiang.Text = "0";//母液数量
            TextBox_Suliang.Text = "0";//转出数量
           // TextBox_Unit.Text = "";//计量单位
            TextBox_ZaiXianPishi.Text = "0";//在线批时
            TextBox_ZaiXianPiShu.Text = "0";//在线批数
            TextBox_ZhuangChuPiShi.Text = "0";//转出批时
            TextBox_ZhuangChuPishu.Text = "0";//转出批数

            MyInputCheck(DropDownList_Check.SelectedValue);

        }

        //保存当前的中间体信息表
        protected void Button_Save_Command(object sender, CommandEventArgs e)
        {

            int CurrentCenterId = Convert.ToInt32(DropDownList_CostCenterId.SelectedValue);

            if (DropDownList_PIPId.SelectedValue == "" || DropDownList_PIPId.SelectedValue == null)
            {
                //Response.Write("<script>alert('当前作业中心的中间产品为空'); </script>");
                alter = "<script>alert('当前作业中心的中间产品为空');</script>";
                return;
            
            }

            var IsLocked = (from a in db.TABC_JS_ProductInProcessDelivery
                            where a.作业中心ID == CurrentCenterId
                            && a.会计期间ID == Application["accountPeriod"].ToString()
                            && a.锁定 == true
                            select a.作业中心ID).Count();
            if (IsLocked > 0 )
            {
                //Response.Write("<script>alert('当前作业中心的中间产品为空'); </script>");
                alter = "<script>alert('当前作业中心已锁定');</script>";
                return;

            }

            var MyqueryCount = (from a in db.TABC_JS_ProductInProcessDelivery
                                where a.会计期间ID == Application["accountPeriod"].ToString() &&
                                    a.作业中心ID == CurrentCenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                                select a).Count();

            if (MyqueryCount == 0)
            {
               // AddFlag.Value = "add"; //判断当前记录不存在，并设置为增加状态

              //  Response.Write("<script>alert('当前作业中心的中间产品没有定义转出路径，请在“作业路径设置”模块检查'); </script>");
                alter = "<script>alert('当前作业中心的中间产品没有定义转出路径，请在“作业路径设置”模块检查');</script>";
                BindMyData();
                return;
            }
            else
            {
                AddFlag.Value = "edit";//判断当前记录存在，并设置为增加状态
            }

            switch (AddFlag.Value)
            {
                case "add":
                    {
                        TABC_JS_ProductInProcessDelivery myrow = new TABC_JS_ProductInProcessDelivery();
                        myrow.会计期间ID = Application["accountPeriod"].ToString();
                        myrow.作业中心ID = Convert.ToInt32(DropDownList_CostCenterId.SelectedValue);
                        myrow.中间体ID = DropDownList_PIPId.SelectedValue;
                        myrow.时间 = DateTime.Now;
                        myrow.操作员ID = Session[ServerVars.sysSessionUserName].ToString();


                        myrow.待返工批时 = Convert.ToDecimal(TextBox_DaiFanGongPishi.Text);//待返工批时
                        myrow.待返工批数 = Convert.ToDecimal(TextBox_DaiFanGongPishu.Text);//待返工批数
                        myrow.待检批时 = Convert.ToDecimal(TextBox_DaiJianPishi.Text);//待检批时
                        myrow.待检批数 = Convert.ToDecimal(TextBox_DaiJianPishu.Text);//待检批数
                        myrow.结存批时 = Convert.ToDecimal(TextBox_JieChunPiShi.Text);//结存批时
                        myrow.结存批数 = Convert.ToDecimal(TextBox_JieChunPiShu.Text);//结存批数
                        myrow.母液回收率 = Convert.ToDecimal(TextBox_MuYeHuiShouLv.Text);//母液回收率
                        myrow.母液数量 = Convert.ToDecimal(TextBox_MuYeShuLiang.Text);//母液数量
                        myrow.转出数量 = Convert.ToDecimal(TextBox_Suliang.Text);//转出数量
                        myrow.计量单位 = TextBox_Unit.Text;//计量单位
                        myrow.在线批时 = Convert.ToDecimal(TextBox_ZaiXianPishi.Text);//在线批时
                        myrow.在线批数 = Convert.ToDecimal(TextBox_ZaiXianPiShu.Text);//在线批数
                        myrow.转出批时 = Convert.ToDecimal(TextBox_ZhuangChuPiShi.Text);//转出批时
                        myrow.转出批数 = Convert.ToDecimal(TextBox_ZhuangChuPishu.Text);//转出批数
                        myrow.损失批数 = Convert.ToDecimal(TextBox_ShunshiPishu.Text);//损失批数
                        myrow.损失批时 = Convert.ToDecimal(TextBox_ShunShiPiShi.Text);//损失批时
                        myrow.计算识别码 = Convert.ToInt32(DropDownList_Check.SelectedValue);

                        #region 不同作业中心的转出路径选择算法
                        switch (DropDownList_Check.SelectedValue)
                        {
                            case "0"://发酵
                                {  //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0 )
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }

                                    break;
                                }

                            /*
                              母液数量*回收率能得到母液的折批数。
                             * 母液折批的批时，是用折批数*转出批数的各批平均批时数。
                             */
                            case "1"://提取、合成  
                                {

                                //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                        try
                                        {double MuYeZhePiShi = (((double)myrow.母液数量* (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 +(decimal) MuYeZhePiShi;
                                        }
                                        catch
                                        {
                                            myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                        }
                                       


                             

                                        if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                        {
                                            myrow.作业成本转出率 = 0;
                                        }
                                        else
                                        {
                                            myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                        }



                                        try
                                        {
                                            double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率)/ ((double)myrow.转出数量 / (double)myrow.转出批数);

                                            myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                        }
                                        catch
                                        {
                                            myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                        }

                                        if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                        {
                                            myrow.材料转出率 = 0;
                                        }
                                        else
                                        {
                                            myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                        }


                                    break;
                                }
                            case "2"://精制
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }
                                    break;
                                }
                            case "3"://板框
                                {
                                   //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0 )
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }

                                    break;
                                }
                            case "4"://气流干燥
                                {
                                    //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0 )
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }


                                    break;
                                }
                            case "5"://合成、氢化、结晶离心
                                {
                                     //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }
                                    break;
                                }
                            case "6"://精制、冻干
                                {
                                     //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }
                                    break;
                                }
                            case "7"://溶媒
                                {

                                    myrow.作业成本转出率 = 1;

                                    myrow.材料转出率 = 1;




                                    break;
                                }
                            case "8"://喷雾
                                {
                                   //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0 )
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }


                                    break;
                                }
                            case "9"://预混、粉剂
                                {
                                    try
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);



                                    }
                                    catch
                                    {
                                        myrow.作业成本转出率 = 1;




                                    }

                                    try
                                    {


                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);

                                    }
                                    catch
                                    {


                                        myrow.材料转出率 = 1;


                                    }



                                    break;
                                }
                            case "10"://樟脑
                                {
                                   //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0 )
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }


                                    break;
                                }
                            case "11"://207
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }

                                    break;
                                }

                            case "12"://中药
                                {
                                     //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时);
                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数);
                                    }
                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }

                        #endregion

                        db.TABC_JS_ProductInProcessDelivery.InsertOnSubmit(myrow);


                        try
                        {
                            db.SubmitChanges();
                         //   Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('保存成功'); </script>");
                            alter = "<script>alert('保存成功');</script>";
                            BindMyData();
                        }
                        catch
                        {
                            alter = "<script>alert('保存失败');</script>";
                           // Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('保存失败'); </script>");

                        }
                        break;

                    }
                case "edit":
                    {
                        int CenterId = Convert.ToInt32(DropDownList_CostCenterId.SelectedValue);


                                   
                        var myrow = (from a in db.TABC_JS_ProductInProcessDelivery
                                where a.会计期间ID == Application["accountPeriod"].ToString() &&
                                    a.作业中心ID == CurrentCenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                                select a).Single();

                        myrow.待返工批时 = Convert.ToDecimal(TextBox_DaiFanGongPishi.Text);//待返工批时
                        myrow.待返工批数 = Convert.ToDecimal(TextBox_DaiFanGongPishu.Text);//待返工批数
                        myrow.待检批时 = Convert.ToDecimal(TextBox_DaiJianPishi.Text);//待检批时
                        myrow.待检批数 = Convert.ToDecimal(TextBox_DaiJianPishu.Text);//待检批数
                        myrow.结存批时 = Convert.ToDecimal(TextBox_JieChunPiShi.Text);//结存批时
                        myrow.结存批数 = Convert.ToDecimal(TextBox_JieChunPiShu.Text);//结存批数
                        myrow.母液回收率 = Convert.ToDecimal(TextBox_MuYeHuiShouLv.Text);//母液回收率
                        myrow.母液数量 = Convert.ToDecimal(TextBox_MuYeShuLiang.Text);//母液数量
                        myrow.转出数量 = Convert.ToDecimal(TextBox_Suliang.Text);//转出数量
                        myrow.计量单位 = TextBox_Unit.Text;//计量单位
                        myrow.在线批时 = Convert.ToDecimal(TextBox_ZaiXianPishi.Text);//在线批时
                        myrow.在线批数 = Convert.ToDecimal(TextBox_ZaiXianPiShu.Text);//在线批数
                        myrow.转出批时 = Convert.ToDecimal(TextBox_ZhuangChuPiShi.Text);//转出批时
                        myrow.转出批数 = Convert.ToDecimal(TextBox_ZhuangChuPishu.Text);//转出批数
                        myrow.计算识别码 = Convert.ToInt32(DropDownList_Check.SelectedValue);
                        myrow.损失批数 = Convert.ToDecimal(TextBox_ShunshiPishu.Text);//损失批数
                        myrow.损失批时 = Convert.ToDecimal(TextBox_ShunShiPiShi.Text);//损失批时
                        myrow.时间 = DateTime.Now;
                        myrow.操作员ID = Session[ServerVars.sysSessionUserName].ToString();

                        #region 不同作业中心的转出路径算法
                        switch (DropDownList_Check.SelectedValue)
                        {
                            case "0"://发酵
                                {  //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时== 0)
                                    {
                                         myrow.作业成本转出率 = 0;
                              //          myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                            //            myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                    
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数== 0)
                                    {
                                        myrow.材料转出率 = 0;
                           //             myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                              //          myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }

                                    break;
                                }

                            /*
                              母液数量*回收率能得到母液的折批数。
                             * 母液折批的批时，是用折批数*转出批数的各批平均批时数。
                             */
                            case "1"://提取、合成  
                                {

                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }






                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                //        myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                //        myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                               //         myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                              //          myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }
                            case "2"://精制
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                 //       myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                              //          myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                            //            myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                            //            myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }
                            case "3"://板框
                                {
                                    //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                              //          myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                             //           myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                               //         myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                //        myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }

                                    break;
                                }
                            case "4"://气流干燥
                                {
                                    //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                //        myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                 //       myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                               //         myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                //        myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }
                            case "5"://合成、氢化、结晶离心
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                //        myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                               //         myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                  //      myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                 //       myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }



                                    break;
                                }
                            case "6"://精制、冻干
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                  //      myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                //        myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }


                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                   //     myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                  //      myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }



                                    break;
                                }
                            case "7"://溶媒
                                {

                                    myrow.作业成本转出率 = 1;
                                    myrow.作业成本损失率 = 0;

                                    myrow.材料转出率 = 1;
                                    myrow.材料损失率 = 0;




                                    break;
                                }
                            case "8"://喷雾
                                {
                                    //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                //        myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                  //      myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                               //         myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                 //       myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }
                            case "9"://预混、粉剂
                                {
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                 //       myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                  //      myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                   //     myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                //        myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }



                                    break;
                                }
                            case "10"://樟脑
                                {
                                    //当转出批时与结存批时同时为零的时候，转出率为零
                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                   //     myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                   //     myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    //    myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                   //     myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }
                            case "11"://207
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                   //     myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                    //    myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }


                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                 //       myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                  //      myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }


                                    break;
                                }

                            case "12"://中药
                                {
                                    //先计算母液折批数，如果计算失败，则结存数仅加在线、待返工、待检
                                    try
                                    {
                                        double MuYeZhePiShi = (((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数)) * ((double)myrow.转出批时 / (double)myrow.转出批数);

                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时 + (decimal)MuYeZhePiShi;
                                    }
                                    catch
                                    {
                                        myrow.结存批时 = myrow.在线批时 + myrow.待返工批时 + myrow.待检批时;
                                    }





                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时 == 0)
                                    {
                                        myrow.作业成本转出率 = 0;
                                  //      myrow.作业成本结存率 = 1;
                                        myrow.作业成本损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.作业成本转出率 = (double)myrow.转出批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                   //     myrow.作业成本结存率 = (double)myrow.结存批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);
                                        myrow.作业成本损失率 = (double)myrow.损失批时 / ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批时);

                                    }



                                    try
                                    {
                                        double MuYeZhePiShu = ((double)myrow.母液数量 * (double)myrow.母液回收率) / ((double)myrow.转出数量 / (double)myrow.转出批数);

                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数 + (decimal)MuYeZhePiShu;

                                    }
                                    catch
                                    {
                                        myrow.结存批数 = myrow.在线批数 + myrow.待返工批数 + myrow.待检批数;
                                    }

                                    if ((double)myrow.转出批时 + (double)myrow.结存批时 + (double)myrow.损失批数 == 0)
                                    {
                                        myrow.材料转出率 = 0;
                                    //    myrow.材料结存率 = 1;
                                        myrow.材料损失率 = 0;
                                    }
                                    else
                                    {
                                        myrow.材料转出率 = (double)myrow.转出批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                     //   myrow.材料结存率 = (double)myrow.材料结存率 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                        myrow.材料损失率 = (double)myrow.损失批数 / ((double)myrow.转出批数 + (double)myrow.结存批数 + (double)myrow.损失批数);
                                    }

                                    break;
                                }
                            default:
                                {
                                    break;
                                }

                        }
                        #endregion 


                        //取上一会计期间
                        string CurrentAccountPeriod = Application["accountPeriod"].ToString();
                        String PriorAccountPeriod = string.Empty;
                        db.取会计期间ID(-1, CurrentAccountPeriod, ref PriorAccountPeriod);

                        //查询出上一期间的W系数。
                        var myPriorRow = from a in db.TABC_JS_ProductInProcessDelivery
                                          where a.会计期间ID == PriorAccountPeriod &&
                                         a.作业中心ID == CurrentCenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                                     select a;
                        //判断上期结存数，是否小于本期录入的总批时数。
                        if (myPriorRow.Count() != 0)
                        {
                            decimal myPrior_JieChunPiShi =(decimal)(myPriorRow.Single().结存批时);

                            decimal MyCurrent_TotalPiShi = (decimal)myrow.结存批时 + (decimal)myrow.损失批时 + (decimal)myrow.转出批时;

                            if (MyCurrent_TotalPiShi < myPrior_JieChunPiShi)
                            {

                                alter = "<script>alert('总批时数：" + string.Format("{0:N2}",MyCurrent_TotalPiShi)
                                    + "小于上期结存批时：" + string.Format("{0:N2}", myPrior_JieChunPiShi) + ",请检查并重新填写');</script>";
                                return;
                            
                            }

                        
                        
                        }

                        try
                        {
                            db.SubmitChanges();
                          //  Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('修改成功'); </script>");
                            alter = "<script>alert('修改成功');</script>";
                            BindMyData();
                        }
                        catch
                        {

                           // Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "message", " <script>alert('修改失败'); </script>");
                            alter = "<script>alert('修改失败');</script>";
                        }
                        break;
                    }

            }
        }


        //删除当前的中间体信息表
 

        protected void Button_Delete_Click(object sender, EventArgs e)
        {
            int CenterId = Convert.ToInt32(DropDownList_CostCenterId.SelectedValue);


            var IsLocked = (from a in db.TABC_JS_ProductInProcessDelivery
                            where a.作业中心ID == CenterId
                            && a.会计期间ID == Application["accountPeriod"].ToString()
                            && a.锁定 == true
                            select a.作业中心ID).Count();
            if (IsLocked > 0)
            {
                alter = "<script>alert('当前作业中心已锁定');</script>";
                return;

            }

            var Myquery = from a in db.TABC_JS_ProductInProcessDelivery
                           where a.会计期间ID == Application["accountPeriod"].ToString() &&
                               a.作业中心ID == CenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                           select a;
            if (Myquery.Count() != 1)
            {

                alter = "<script>alert('没有可删除的数据');</script>";

                return;
            }
            else if (Myquery.Count() == 1)
            {
                var MyDelRow = Myquery.Single();

                MyDelRow.待返工批时 = 0;//待返工批时
                MyDelRow.待返工批数 = 0;//待返工批数
                MyDelRow.待检批时 = 0;//待检批时
                MyDelRow.待检批数 = 0;//待检批数
                MyDelRow.结存批时 = 0;//结存批时
                MyDelRow.结存批数 =0;//结存批数
                MyDelRow.母液回收率 = 0;//母液回收率
                MyDelRow.母液数量 = 0;//母液数量
                MyDelRow.转出数量 =0;//转出数量
                //myrow.计量单位 = TextBox_Unit.Text;//计量单位
                MyDelRow.在线批时 =0;//在线批时
                MyDelRow.在线批数 =0;//在线批数
                MyDelRow.转出批时 = 0;//转出批时
                MyDelRow.转出批数 =0;//转出批数
                MyDelRow.损失批时 = 0;
                MyDelRow.损失批数 = 0;
                MyDelRow.时间 = DateTime.Now;
                MyDelRow.操作员ID = Session[ServerVars.sysSessionUserName].ToString();

           //     MyDelRow.计算识别码 = Convert.ToInt32(DropDownList_Check.SelectedValue);



                try
                {
                    db.SubmitChanges();
                  //  Response.Write("<script>alert('删除成功');</script>");
                    alter = "<script>alert('删除成功');</script>";
                    BindMyData();
                }
                catch
                {



                }
            
            
            }
            

        }



        private void BindMyData()
        {
            int CenterId = Convert.ToInt32(DropDownList_CostCenterId.SelectedValue);

      
            var MyqueryCount = (from a in db.TABC_JS_ProductInProcessDelivery
                           where a.会计期间ID == Application["accountPeriod"].ToString() &&
                               a.作业中心ID == CenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                           select a).Count();

            var MyQueryUnite = (from a in db.TABC_JS_ProductInProcess
                                where a.作业中心ID == CenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                                select a.计量单位).Single();

            if (MyqueryCount == 0)
            {

                //当前中间体没有记录的时候，所有编辑页清零。
                TextBox_DaiFanGongPishi.Text = "0";//待返工批时
                TextBox_DaiFanGongPishu.Text = "0";//待返工批数
                TextBox_DaiJianPishi.Text = "0";//待检批时
                TextBox_DaiJianPishu.Text = "0";//待检批数
                TextBox_JieChunPiShi.Text = "0";//结存批时
                TextBox_JieChunPiShu.Text = "0";//结存批数
                TextBox_MuYeHuiShouLv.Text = "0";//母液回收率
                TextBox_MuYeShuLiang.Text = "0";//母液数量
                TextBox_Suliang.Text = "0";//转出数量

                if (MyQueryUnite.ToString() != "")
                {      TextBox_Unit.Text = MyQueryUnite.ToString();}
                else
                {     TextBox_Unit.Text = ""; }
           
                TextBox_ZaiXianPishi.Text = "0";//在线批时
                TextBox_ZaiXianPiShu.Text = "0";//在线批数
                TextBox_ZhuangChuPiShi.Text = "0";//转出批时
                TextBox_ZhuangChuPishu.Text = "0";//转出批数

                DropDownList_Check.SelectedValue = "";

            //    AddFlag.Value = "add";//保存当前的控制状态为新增
            }
            else
            {
                var Myquery = (from a in db.TABC_JS_ProductInProcessDelivery
                               where a.会计期间ID == Application["accountPeriod"].ToString() &&
                                   a.作业中心ID == CenterId && a.中间体ID == DropDownList_PIPId.SelectedValue
                               select a).Single();

                MyInputCheck(Myquery.计算识别码.ToString());//通过识别码，封锁相关的文本框
                DropDownList_Check.SelectedValue = Myquery.计算识别码.ToString();

                TextBox_DaiFanGongPishi.Text = String.Format("{0:F4}", Myquery.待返工批时);//待返工批时
                TextBox_DaiFanGongPishu.Text = String.Format("{0:F4}", Myquery.待返工批数);//待返工批数
                TextBox_DaiJianPishi.Text = String.Format("{0:F4}", Myquery.待检批时);//待检批时
                TextBox_DaiJianPishu.Text = String.Format("{0:F4}", Myquery.待检批数);//待检批数
                TextBox_JieChunPiShi.Text = String.Format("{0:F4}", Myquery.结存批时);//结存批时
                TextBox_JieChunPiShu.Text = String.Format("{0:F4}", Myquery.结存批数);//结存批数
                TextBox_MuYeHuiShouLv.Text = String.Format("{0:F4}", Myquery.母液回收率);//母液回收率
                TextBox_MuYeShuLiang.Text = String.Format("{0:F4}", Myquery.母液数量);//母液数量
                TextBox_Suliang.Text = String.Format("{0:F4}", Myquery.转出数量);//转出数量
             //   TextBox_Unit.Text = Myquery.计量单位;//计量单位

                if (MyQueryUnite.ToString() != "")
                { TextBox_Unit.Text = MyQueryUnite.ToString(); }
                else
                { TextBox_Unit.Text = ""; }

                TextBox_ZaiXianPishi.Text = String.Format("{0:F4}", Myquery.在线批时);//在线批时
                TextBox_ZaiXianPiShu.Text = String.Format("{0:F4}", Myquery.在线批数);//在线批数
                TextBox_ZhuangChuPiShi.Text = String.Format("{0:F4}", Myquery.转出批时);//转出批时
                TextBox_ZhuangChuPishu.Text = String.Format("{0:F4}", Myquery.转出批数);//转出批数
                TextBox_ShunShiPiShi.Text = string.Format("{0:F4}", Myquery.损失批时);
                TextBox_ShunshiPishu.Text = string.Format("{0:F4}", Myquery.损失批数);


                HiddenField_MyID.Value = Myquery.ID.ToString();



          //      AddFlag.Value = "edit";//保存当前的控制状态为编辑



            }



        }
        //
        protected void Button_Query_Click(object sender, EventArgs e)
        {
            BindMyData();
        }

        #region   //按计算识别码来判断当前录入界面的标签及可输入性。
        private void MyInputCheck(string CheckId)
        {
            switch (CheckId)
            {
                case "0"://发酵
                    {


                        //TextBox_Unit.Text = Myquery.计量单位;//计量单位
                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text= "发酵液净重"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时

                        break;
                    }
                case "1"://提取、合成
                    {


                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                        TextBox_DaiJianPishi.Enabled = true;//待检批时
                        TextBox_DaiJianPishu.Enabled = true;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = true;//母液数量
                        TextBox_ZaiXianPishi.Enabled = true;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "粗品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "2"://精制
                    {



                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                        TextBox_DaiJianPishi.Enabled = true;//待检批时
                        TextBox_DaiJianPishu.Enabled = true;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = true;//母液数量
                        TextBox_ZaiXianPishi.Enabled = true;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "3"://板框
                    {


                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "数量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "4"://气流干燥
                    {


                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "数量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "5"://合成、氢化、结晶离心


                    TextBox_Suliang.Enabled = true;//转出数量
                    TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                    TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                    TextBox_DaiJianPishi.Enabled = true;//待检批时
                    TextBox_DaiJianPishu.Enabled = true;//待检批数
                    TextBox_JieChunPiShi.Enabled = false;//结存批时
                    TextBox_JieChunPiShu.Enabled = false;//结存批数
                    TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                    TextBox_MuYeShuLiang.Enabled = true;//母液数量
                    TextBox_ZaiXianPishi.Enabled = true;//在线批时
                    TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                    TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                    TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                    Label_Amount.Text = "转出品重量"; //数量
                    Label_daifangongpishi.Text = "待返工批时";//待返工批时
                    Label_daifangongpishu.Text = "待返工批数";//待返工批数
                    Label_daijianpishi.Text = "待检批时";//待检批时
                    Label_daijianpishu.Text = "待检批数";//待检批数
                    Label_jiechunpishi.Text = "结存批时";//结存批时
                    Label_jiechunpishu.Text = "结存批数";//结存批数
                    Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                    Label_muyeshuliang.Text = "母液重量";//母夜数量
                    Label_zaixianpishi.Text = "在线批时";//在线批时
                    Label_ZaiXianPishu.Text = "在线批数";//在线批数
                    Label_zhuangchuPishu.Text = "转出批数";//
                    Label_zhuanqupishi.Text = "转出批时";//转出批时
                    { break; }
                case "6"://精制冻干
                    {
                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                        TextBox_DaiJianPishi.Enabled = true;//待检批时
                        TextBox_DaiJianPishu.Enabled = true;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = true;//母液数量
                        TextBox_ZaiXianPishi.Enabled = true;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "7"://溶媒回收
                    {



                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = false;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = false;//转出批数

                        Label_Amount.Text = "待回收溶媒重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "8"://喷雾干燥
                    {


                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "转出品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "9"://预混、粉剂
                    {



                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "10"://樟脑、分装、粉碎
                    {




                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = false;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = false;//待返工批数
                        TextBox_DaiJianPishi.Enabled = false;//待检批时
                        TextBox_DaiJianPishu.Enabled = false;//待检批数
                        TextBox_JieChunPiShi.Enabled = true;//结存批时
                        TextBox_JieChunPiShu.Enabled = true;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = false;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = false;//母液数量
                        TextBox_ZaiXianPishi.Enabled = false;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = false;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "11"://207
                    {



                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                        TextBox_DaiJianPishi.Enabled = true;//待检批时
                        TextBox_DaiJianPishu.Enabled = true;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = true;//母液数量
                        TextBox_ZaiXianPishi.Enabled = true;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }
                case "12"://中药
                    {
                        TextBox_Suliang.Enabled = true;//转出数量
                        TextBox_DaiFanGongPishi.Enabled = true;//待返工批时
                        TextBox_DaiFanGongPishu.Enabled = true;//待返工批数
                        TextBox_DaiJianPishi.Enabled = true;//待检批时
                        TextBox_DaiJianPishu.Enabled = true;//待检批数
                        TextBox_JieChunPiShi.Enabled = false;//结存批时
                        TextBox_JieChunPiShu.Enabled = false;//结存批数
                        TextBox_MuYeHuiShouLv.Enabled = true;//母液回收率
                        TextBox_MuYeShuLiang.Enabled = true;//母液数量
                        TextBox_ZaiXianPishi.Enabled = true;//在线批时
                        TextBox_ZaiXianPiShu.Enabled = true;//在线批数
                        TextBox_ZhuangChuPiShi.Enabled = true;//转出批时
                        TextBox_ZhuangChuPishu.Enabled = true;//转出批数

                        Label_Amount.Text = "成品重量"; //数量
                        Label_daifangongpishi.Text = "待返工批时";//待返工批时
                        Label_daifangongpishu.Text = "待返工批数";//待返工批数
                        Label_daijianpishi.Text = "待检批时";//待检批时
                        Label_daijianpishu.Text = "待检批数";//待检批数
                        Label_jiechunpishi.Text = "结存批时";//结存批时
                        Label_jiechunpishu.Text = "结存批数";//结存批数
                        Label_muyehuishoulv.Text = "母液折纯系数";//母液回收率
                        Label_muyeshuliang.Text = "母液重量";//母夜数量
                        Label_zaixianpishi.Text = "在线批时";//在线批时
                        Label_ZaiXianPishu.Text = "在线批数";//在线批数
                        Label_zhuangchuPishu.Text = "转出批数";//
                        Label_zhuanqupishi.Text = "转出批时";//转出批时
                        break;
                    }

                default:
                    { break; }
            }

        }

        #endregion

        protected void DropDownList_CostCenterId_SelectedIndexChanged(object sender, EventArgs e)
        {
            //当作业中心变化的时候，要清空当前的填充页面。
            //当前中间体没有记录的时候，所有编辑页清零。
            TextBox_DaiFanGongPishi.Text = "0";//待返工批时
            TextBox_DaiFanGongPishu.Text = "0";//待返工批数
            TextBox_DaiJianPishi.Text = "0";//待检批时
            TextBox_DaiJianPishu.Text = "0";//待检批数
            TextBox_JieChunPiShi.Text = "0";//结存批时
            TextBox_JieChunPiShu.Text = "0";//结存批数
            TextBox_MuYeHuiShouLv.Text = "0";//母液回收率
            TextBox_MuYeShuLiang.Text = "0";//母液数量
            TextBox_Suliang.Text = "0";//转出数量
            TextBox_Unit.Text = "";//计量单位
            TextBox_ZaiXianPishi.Text = "0";//在线批时
            TextBox_ZaiXianPiShu.Text = "0";//在线批数
            TextBox_ZhuangChuPiShi.Text = "0";//转出批时
            TextBox_ZhuangChuPishu.Text = "0";//转出批数

            DropDownList_Check.SelectedValue = "";
        }





    }
}
